<template>
  <app-navbar />
  <div class="merch-management-layout">
    <side-bar v-if="isLoggedIn" />
    <div class="merch-management-view">
      <h2>周边商品管理</h2>
      <div class="actions-bar">
        <button class="add-btn">+ 添加新商品</button>
      </div>
      <div class="merch-table">
        <div class="merch-table-header">
          <span>图片</span>
          <span>商品名称</span>
          <span>类型</span>
          <span>价格</span>
          <span>状态</span>
          <span>操作</span>
        </div>
        <div v-for="item in merchs" :key="item.id" class="merch-table-row">
          <img :src="item.img" class="merch-cover" />
          <span class="merch-title">{{ item.title }}</span>
          <span class="merch-type">{{ item.type }}</span>
          <span class="merch-price">￥{{ item.price }}</span>
          <span>
            <span :class="['status', item.inStock ? 'on' : 'off']">{{ item.inStock ? '在售' : '下架' }}</span>
          </span>
          <span class="actions">
            <button @click="toggleStatus(item)" class="status-btn">
              {{ item.inStock ? '下架' : '上架' }}
            </button>
            <button class="edit-btn">编辑</button>
            <button class="delete-btn">删除</button>
          </span>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup>
import { ref } from 'vue'
import AppNavbar from '@/components/AppNavbar.vue'
import SideBar from '@/components/SideBar.vue'

const isLoggedIn = ref(sessionStorage.getItem('isLoggedIn') === 'true')

const merchs = ref([
  {
    id: 1,
    title: '星际远征定制手办',
    img: 'https://images.unsplash.com/photo-1519125323398-675f0ddb6308?auto=format&fit=crop&w=400&q=80',
    type: '手办',
    price: 199,
    inStock: true,
  },
  {
    id: 2,
    title: '机械迷城主题T恤',
    img: 'https://images.unsplash.com/photo-1508766206392-8bd5cf550d1d?auto=format&fit=crop&w=400&q=80',
    type: '服饰',
    price: 89,
    inStock: false,
  },
  {
    id: 3,
    title: '极速竞速鼠标垫',
    img: 'https://images.unsplash.com/photo-1464983953574-0892a716854b?auto=format&fit=crop&w=400&q=80',
    type: '外设',
    price: 59,
    inStock: true,
  },
  {
    id: 4,
    title: '魔法世界钥匙扣',
    img: 'https://images.unsplash.com/photo-1511512578047-dfb367046420?auto=format&fit=crop&w=400&q=80',
    type: '饰品',
    price: 29,
    inStock: true,
  },
])

function toggleStatus(item) {
  item.inStock = !item.inStock
}
</script>

<style scoped>
.merch-management-layout {
  display: flex;
  flex-direction: row;
  width: 100vw;
  min-height: 100vh;
  background: linear-gradient(135deg, #181a20 60%, #232946 100%);
  justify-content: center;
}
.merch-management-view {
  flex: 1;
  margin-left: 180px;
  padding: 56px 0 32px 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  min-height: 100vh;
  width: 100%;
  box-sizing: border-box;
  background: linear-gradient(135deg, #181a20 60%, #232946 100%);
}
.merch-management-view h2 {
  color: #a3b8d8;
  font-size: 2.4rem;
  margin-bottom: 36px;
  letter-spacing: 2px;
  text-shadow: 0 2px 18px #3a4a6a44, 0 0 2px #232946;
  font-weight: 700;
  transition: color 0.3s;
}
.actions-bar {
  margin-bottom: 28px;
  text-align: right;
  width: 100%;
  max-width: 1200px;
}
.add-btn {
  background: linear-gradient(90deg, #4e8cff 0%, #6ed0ff 100%);
  color: #232946;
  border: none;
  border-radius: 8px;
  padding: 10px 28px;
  font-size: 1.08rem;
  font-weight: bold;
  cursor: pointer;
  box-shadow: 0 2px 12px #4e8cff33;
  transition: background 0.3s, box-shadow 0.3s, transform 0.2s;
}
.add-btn:hover {
  background: linear-gradient(90deg, #6ed0ff 0%, #4e8cff 100%);
  box-shadow: 0 6px 24px #4e8cff66;
  transform: translateY(-2px) scale(1.04);
}
.merch-table {
  background: rgba(24,26,32,0.97);
  border-radius: 24px;
  box-shadow: 0 8px 40px 0 #4e8cff22, 0 0 0 2px #232946;
  border: 1.5px solid #232946;
  padding: 0 0 18px 0;
  min-width: 90vw;
  max-width: 90vw;
  margin: 0 auto;
  transition: box-shadow 0.3s;
  padding-left: 48px;
}
.merch-table-header, .merch-table-row {
  display: grid;
  grid-template-columns: 100px 2fr 1fr 1fr 1fr 2.2fr;
  align-items: center;
  gap: 18px;
  padding: 20px 36px;
  text-align: center;
}
.merch-table-header span, .merch-table-row > * {
  display: flex;
  justify-content: center;
  align-items: center;
  text-align: center;
  width: 100%;
}
.merch-title, .merch-type, .merch-price {
  justify-content: center;
  align-items: center;
  display: flex;
  text-align: center;
  width: 100%;
}
.status {
  padding: 6px 18px;
  border-radius: 16px;
  font-size: 1.05rem;
  font-weight: bold;
  background: #232946;
  color: #7fa7d6;
  margin-right: 8px;
  box-shadow: 0 1px 6px #4e8cff22;
  transition: background 0.2s, color 0.2s;
}
.status.off {
  background: #444a5a;
  color: #bbb;
}
.actions button {
  margin-right: 10px;
  padding: 8px 18px;
  border-radius: 8px;
  border: none;
  font-size: 1.05rem;
  cursor: pointer;
  transition: background 0.2s, color 0.2s, box-shadow 0.2s, transform 0.2s;
  box-shadow: 0 1px 6px #4e8cff22;
}
.status-btn {
  background: linear-gradient(90deg, #7fa7d6 0%, #4e8cff 100%);
  color: #232946;
}
.status-btn:hover {
  background: linear-gradient(90deg, #4e8cff 0%, #7fa7d6 100%);
  color: #fff;
  box-shadow: 0 4px 16px #4e8cff55;
  transform: scale(1.05);
}
.edit-btn {
  background: #232946;
  color: #7fa7d6;
}
.edit-btn:hover {
  background: #4e8cff;
  color: #fff;
  box-shadow: 0 4px 16px #4e8cff55;
  transform: scale(1.05);
}
.delete-btn {
  background: #444a5a;
  color: #fff;
}
.delete-btn:hover {
  background: #ff4d4f;
  color: #fff;
  box-shadow: 0 4px 16px #ff4d4f55;
  transform: scale(1.05);
}
.merch-table-header span,
.merch-table-row > *,
.merch-title,
.merch-type,
.merch-price,
.status,
.status.on,
.status.off {
  color: #fff !important;
}
@media (max-width: 900px) {
  .merch-management-view {
    padding: 24px 0 16px 0;
  }
  .merch-table {
    min-width: 98vw;
    max-width: 100vw;
    border-radius: 0;
    padding-left: 0;
  }
  .merch-table-header, .merch-table-row {
    padding: 12px 4vw;
    grid-template-columns: 60px 1.2fr 0.8fr 0.8fr 0.8fr 1.5fr;
  }
}
</style> 